package com.ag.hmk.action;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import com.ag.bean.TbPlanStandard;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.hmk.service.PlanStandardService;

/**
 * 
 * @author hmk 预案启动标准action
 */
public class PlanStandardAction extends BaseAction {

	private static final long serialVersionUID = -3345312953915399553L;

	private PlanStandardService planStandardService;
	@Resource(name = "iDServiceImpl")
	private IIDService idservice;
	
	private TbPlanStandard planStandard = new TbPlanStandard();
	private String psID;
	private String ajaxStr;
	private List<TbPlanStandard> planstandardList ;
		
	/*
	 * 保存预案启动标准
	 */
	public String save() throws Exception {
		this.ajaxStr = "0";
		try {
			planStandard.setElId(idservice.findTablePK(IDUtil.TB_PLAN_STANDARD));
			planStandard.setA(IDUtil.PRESERVE);
			if (planStandardService.save(planStandard)) {
				this.ajaxStr = "1";
			} 
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxStr="0";
		}
		return "savePSok";
	}

	/*
	 * 更新预案启动标准
	 */
	public String update() throws Exception {
		this.ajaxStr = "0";
		try {
			if (planStandardService.save(planStandard)) {
				this.ajaxStr = "1";
			} 
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxStr="0";
		}
		
		return "updatePSok";
	}

	/*
	 * 查询预案启动标准（by id）
	 */
	public String findByID() throws Exception {
		try {
			planStandard = planStandardService.findByID(psID);
		} catch (Exception e) {
			e.printStackTrace();
			planStandard = null;
		}
		
		return  "findOnePSok";
	}

	/*
	 * 查询预案启动标准（find all）
	 */
	public String findALL() throws Exception {
		List<TbPlanStandard> list =null;
		try {
			list = planStandardService.findAll();
			/*
			if (list!=null) {
				Iterator<TbPlanStandard> iIterator = list.iterator();
				while(iIterator.hasNext()){
					TbPlanStandard tttStandard = (TbPlanStandard)iIterator.next();
					System.out.println("==="+tttStandard.getElId());
				}
			}
			*/
		} catch (Exception e) {
			e.printStackTrace();
			list=null;
		}
		this.setPlanstandardList(list);
		return "findAllPSok";
	}
	
	/*
	 * 删除预案启动标准（delete  by id）
	 */
	public String delete() throws Exception {
		this.ajaxStr = "0";
		try {
			if (planStandardService.delete(psID)) {
				this.ajaxStr = "1";
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxStr = "0";
		}
		return "deletePSok";
	}

	public void setPlanStandardService(PlanStandardService planStandardService) {
		this.planStandardService = planStandardService;
	}

	public TbPlanStandard getPlanStandard() {
		return planStandard;
	}

	public void setPlanStandard(TbPlanStandard planStandard) {
		this.planStandard = planStandard;
	}

	public String getAjaxStr() {
		return ajaxStr;
	}

	public void setAjaxStr(String ajaxStr) {
		this.ajaxStr = ajaxStr;
	}


	public void setPsID(String psID) {
		this.psID = psID;
	}

	public List<TbPlanStandard> getPlanstandardList() {
		return planstandardList;
	}

	public void setPlanstandardList(List<TbPlanStandard> planstandardList) {
		this.planstandardList = planstandardList;
	}

}
